Completed
Push — master ( 2281e8...8b163e )
by Justin
01:35
created

Coverage.setTemporal   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
rs 9.4285
1
var ExtensibleData = require('./ExtensibleData'),
2
    GDate = require('./Date'),
3
    PlaceReference = require('./PlaceReference'),
4
    utils = require('./utils');
5
6
/**
7
 * A description of the spatial and temporal coverage of a resource.
8
 * 
9
 * @constructor
10
 * @apram {Object} [json]
11
 */
12
var Coverage = function(json){
13
  
14
  // Protect against forgetting the new keyword when calling the constructor
15
  if(!(this instanceof Coverage)){
16
    return new Coverage(json);
17
  }
18
  
19
  // If the given object is already an instance then just return it. DON'T copy it.
20
  if(Coverage.isInstance(json)){
21
    return json;
22
  }
23
  
24
  ExtensibleData.call(this, json);
25
  
26
  if(json){
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if json is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
27
    this.setSpatial(json.spatial);
28
    this.setTemporal(json.temporal);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
29
  }
30
};
31
32
Coverage.prototype = Object.create(ExtensibleData.prototype);
33
34
Coverage._gedxClass = Coverage.prototype._gedxClass = 'GedcomX.Coverage';
35
36
/**
37
 * Check whether the given object is an instance of this class.
38
 * 
39
 * @param {Object} obj
40
 * @returns {Boolean}
41
 */
42
Coverage.isInstance = function(obj){
43
  return utils.isInstance(obj, this._gedxClass);
44
};
45
46
/**
47
 * Get the spatial coverage
48
 * 
49
 * @returns {PlaceReference}
50
 */
51
Coverage.prototype.getSpatial = function(){
52
  return this.spatial;
53
};
54
55
/**
56
 * Set the spatial coverage
57
 * 
58
 * @param {PlaceReference} spatial
59
 * @returns {Coverage}
60
 */
61
Coverage.prototype.setSpatial = function(spatial){
62
  if(spatial){
63
    this.spatial = PlaceReference(spatial);
64
  }
65
  return this;
66
};
67
68
/**
69
 * Get the temporal coverage
70
 * 
71
 * @returns {Date}
72
 */
73
Coverage.prototype.getTemporal = function(){
74
  return this.temporal;
75
};
76
77
/**
78
 * Set the temporal coverage
79
 * 
80
 * @param {Date} temporal
81
 * @returns {Coverage}
82
 */
83
Coverage.prototype.setTemporal = function(temporal){
84
  if(temporal){
85
    this.temporal = GDate(temporal);
86
  }
87
  return this;
88
};
89
90
/**
91
 * Export the object as JSON
92
 * 
93
 * @return {Object} JSON object
94
 */
95
Coverage.prototype.toJSON = function(){
96
  var json = ExtensibleData.prototype.toJSON.call(this);
97
  
98
  if(this.spatial){
99
    json.spatial = this.spatial.toJSON();
100
  }
101
  
102
  if(this.temporal){
103
    json.temporal = this.temporal.toJSON();
104
  }
105
  
106
  return json;
107
};
108
109
module.exports = Coverage;